/*
 * Copyright 2006 Berry Crawford
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.judo.properties;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;

public class Props
{
	private static HashMap props = new HashMap();
	
	public static void property(String name,String value)
	{
		props.put(name,value);
	}
	
	public static Iterator<String> propNames()
	{
		return props.keySet().iterator();
	}
	
	public static String get(String name)
	{
		return (String)props.get(name);
	}
	
	public static void load()
	{
		try
		{
			InputStream is = null;
			
			try
			{	
				is = Props.class.getResourceAsStream("/judo.properties");
				Properties newProps = new Properties();
				newProps.load(is);
				props.putAll(newProps);
				
				String otherProps = (String)props.get("other.property.files");
				String propFiles[] = otherProps.split(",");
				
				for(String propFile: propFiles)
				{
					InputStream is2 = null;
					
					try
					{
						is2 = Props.class.getResourceAsStream(propFile);
						newProps.load(is2);
						props.putAll(newProps);
					}
					finally{
						if (is2 != null)
							is2.close();
					}
				}
			}
			finally{
				is.close();
			}
		}
		catch(Exception e)
		{
			System.out.println("Error loading Resouces: "+e);
			e.printStackTrace();
		}
	}
}
